(function(){
    angular.module('app').controller("activeCtrl",function($scope,proxy,$stateParams){
        console.log(PERMISSION);
        $scope.newOrder = function (item) {
            sessionStorage.step = 1;
            layer.open({
                type: 1,
                title: "新建广告订单",
                skin: "layer-style",
                area: ['660px', '380px'], //宽高
                content: $(".orderType")
            });
            $scope.activeId = item.activityID;
            $scope.activeName = item.name;
        };
        $scope.clearLayer = function () {
            layer.closeAll();
        };
        // 全选状态
        $scope.allCheck = false;
        $scope.activeIDs = [];
        $scope.obj={
            'sTime':getNowFormatDate()+' '+'00:00:00', //默认今日
            'eTime':getNowFormatDate()+' '+'23:59:59',
            'permission':PERMISSION,
        };
        $scope.checks = ["1"];
        $scope.radios = 2;
        $scope.select = [
            {
                id:'10,20',
                name:"全部"
            },
            {
                id:'10',
                name:"开启"
            },
            {
                id:'20',
                name:"暂停"
            }
        ];
        $scope.searchVal = "";
        $scope.search = [
            {
                name:"下拉框查询1"
            },
            {
                name:"下拉框查询2"
            },
            {
                name:"下拉框查询3"
            }
        ];
        // 素材全选事件
        $scope.allCheckFunc = function(checked){
            $scope.activeIDs = [];
            if(checked) {
                $(".activeFlag").each(function(){
                    $scope.activeIDs.push($(this).attr("value"));
                })
            }
        };
        // 素材点击事件
        $scope.checkFunc = function() {
            // 素材框全勾选时,勾选全选框
            $scope.allCheck = $scope.activeIDs.length == $(".activeFlag").length;
        };
        //修改活动状态
        $scope.setStatus = function(item){
            proxy.proxy({
                url: STATIC_URL.domian+'/dsp/activity/modify',
                data: {
                    data:{
                        state:item.state=='10'?'20':'10','activityID':item.activityID
                    }
                },
                success: function(res){
                    item.state=='10'?'20':'10';
                }
            })
        };
        //修改频次
        $scope.changeFre = function(item,num){
            proxy.proxy({
                url: STATIC_URL.domian+'/dsp/activity/modify',
                data: {
                    data:{
                        frequency:num,'activityID':item.activityID
                    }
                },
                success: function(res){
                    item.frequency=num;
                    item.editFlag = !item.editFlag;
                }
            })

        };
        //时间过滤
        $scope.chooseDate = function(sTime,eTime){
            $scope.obj.sTime = sTime+' '+'00:00:00';
            $scope.obj.eTime = eTime+' '+'23:59:59';
            getList();
        };
        //状态过滤
        $scope.chooseStatus = function(item){
            $scope.obj.status= item.id;
            getList();
        };
        getList();
        function getList(current, pagesize) {
            var data = {
                'page': (current || 1)+"",
                'size': (pagesize || 20)+"",
                'filter':{
                    'state': $scope.obj.status,
                },
                //'sTime' : $scope.obj.sTime,
                //'eTime' : $scope.obj.eTime,
                "sort": ["cTime,1"],
            };
            proxy.proxy({
                url: STATIC_URL.domian+'/dsp/activity/list',
                data: data,
                load:true,
                success: function(res){
                    // 获得列表
                    $scope.activelist = res.data.data;
                    $("#pageToolbar").html("");
                    $('#pageToolbar').Paging({pagesize: pagesize || '20',current: current || '1',count:res.data.total,toolbar:true,'hash': false,
                        callback:getList});
                }
            })
        };
    })
})();

